#include "StdAfx.h"
#include "DeviceManager.h"


IDirect3DDevice9* DeviceManager::pdevice=NULL;
DeviceManager::DeviceManager(void)
{
}

IDirect3DDevice9* WINAPI DeviceManager::CreateDevice(HWND hwindow,bool windowed){
	if(NULL!=pdevice){
		return pdevice;
	}
	IDirect3D9 *_d3d=Direct3DCreate9(D3D_SDK_VERSION);
	D3DPRESENT_PARAMETERS d3dpp;
	ZeroMemory(&d3dpp,sizeof(D3DPRESENT_PARAMETERS));
	d3dpp.BackBufferWidth=1024;
	d3dpp.BackBufferHeight=768;
	
	d3dpp.BackBufferFormat=D3DFMT_A8R8G8B8;
	d3dpp.EnableAutoDepthStencil=TRUE;
	d3dpp.AutoDepthStencilFormat=D3DFMT_D24S8;
	
	
	d3dpp.Windowed=windowed;
	d3dpp.BackBufferCount=1;
	d3dpp.hDeviceWindow=hwindow;
	d3dpp.SwapEffect=D3DSWAPEFFECT_DISCARD;
	HRESULT hr=_d3d->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,hwindow,D3DCREATE_SOFTWARE_VERTEXPROCESSING,&d3dpp,&pdevice);
	char temp[100];
	_ltoa_s(hr,temp,10);
	wchar_t wtemp[50];
	mbstowcs_s(NULL,wtemp,temp,50);
	//_sprint
	OutputDebugString(wtemp);
	_d3d->Release();
	_d3d=NULL;
	
	return pdevice;
}

DeviceManager::~DeviceManager(void)
{
}


void DeviceManager::CleanUp(void)
{
	if(pdevice){pdevice->Release();pdevice=NULL;}
}

IDirect3DDevice9* WINAPI DeviceManager::GetDevice()
{
	return pdevice;
}
